package com.huaru.formboot.form.controller;


import com.huaru.formboot.form.entity.Dto.TableTemplate;
import com.huaru.formboot.form.entity.vo.TableTemplateVo;
import com.huaru.formboot.form.service.TableTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 表单模板表 前端控制器
 * </p>
 *
 * @author wz
 * @since 2021-04-15
 */
@Api(tags = "采集表单模板相关接口")
@RestController
@RequestMapping("/form/table-template")
public class TableTemplateController {
    /**
     * 表单模板服务
     */
    @Autowired
    private TableTemplateService tableTemplateService;

    @ApiOperation("采集表单模板树接口")
    @PostMapping("/getTableList")
    public List<TableTemplateVo> getTableList(){

        return tableTemplateService.getAllTableTemplate();
    }

    @ApiOperation("采集表单模板添加根节点接口")
    @PostMapping("/insertRootNode")
    public Integer insertRootNode(@RequestBody TableTemplate tableTemplate){
        return tableTemplateService.insertRootNode(tableTemplate);
    }

    @ApiOperation("采集表单模板添加下级节点接口")
    @PostMapping("/insertLowerNode")
    public Integer insertLowerNode(@RequestBody TableTemplate tableTemplate){
        return tableTemplateService.insertLowerNode(tableTemplate);
    }

    @ApiOperation("采集表单模板编辑节点接口")
    @PostMapping("/updateNode")
    public Integer updateNode(@RequestBody TableTemplate tableTemplate){
        return tableTemplateService.updateNode(tableTemplate);
    }

    @ApiOperation("采集表单模板删除节点接口")
    @PostMapping("/deletedNode")
    public Integer deletedNode(@RequestBody TableTemplate tableTemplate){
        return tableTemplateService.deletedNode(tableTemplate.getTableId());
    }

    @ApiOperation("保存采集表单模板接口")
    @PostMapping("/save")
    public Integer save(@RequestBody TableTemplate tableTemplate){

        return tableTemplateService.updateNode(tableTemplate);
    }
}

